<template>
	<view class="page" :style="{'min-height':(h-mt)+'px','padding-top':mt+'px'}">
		<c-nav-bar title="拼船"></c-nav-bar>
		<view class="jd_sticky" :style="{'top':mt+'px'}">
			<view class="searchCondition">
				<view class="item" @click="sortTime()">
					<u-icon name="arrow-down-fill" size="19" label="出发时间" labelPos="left" labelSize="13px"
						v-if="!timeNum"></u-icon>
					<u-icon name="arrow-up-fill" size="19" label="出发时间" labelPos="left" labelSize="13px" v-else
						customStyle="color:#007A69" labelColor="#007A69"></u-icon>
				<!-- 	<view v-if="timeNum==0">
						<text>出发时间</text>
						<image :src="jt"></image>
					</view>
					<view v-if="timeNum==1">
						<text>出发时间</text>
						<image :src="jtb"></image>
					</view>
					<view v-if="timeNum==2">
						<text>出发时间</text>
						<image :src="jtt"></image>
					</view> -->
				</view>
				<view class="item" @click="sortPrice()">
					<u-icon name="arrow-down-fill" size="19" label="价格" labelPos="left" labelSize="13px"
						v-if="!pricesort"></u-icon>
					<u-icon name="arrow-up-fill" size="19" label="价格" labelPos="left" labelSize="13px" v-else
						customStyle="color:#007A69" labelColor="#007A69"></u-icon>
					<!-- <view v-if="pricesort==0">
						<text>价格</text>
						<image :src="jt"></image>
					</view>
					<view v-if="pricesort==1">
						<text>价格</text>
						<image :src="jtb"></image>
					</view>
					<view v-if="pricesort==2">
						<text>价格</text>
						<image :src="jtt"></image>
					</view> -->
				</view>
				<view class="item" @click="sortNum()">
					<u-icon name="arrow-down-fill" size="19" label="人数" labelPos="left" labelSize="13px"
						v-if="!numSort"></u-icon>
					<u-icon name="arrow-up-fill" size="19" label="人数" labelPos="left" labelSize="13px" v-else
						customStyle="color:#007A69" labelColor="#007A69"></u-icon>
				</view>

			</view>
		</view>
		<view style="margin-top:20rpx">
			<view class="list" v-for="(item, index) in data" :key="index">
				<view class="card">
					<text class="me" v-if="openId==item.openId">我发布的</text>
					<view class="card_pic">
						<image :src="item.coverImg||jt" mode="" class="goods"></image>
					</view>
					<view class="card_text">
						<view class="num">还差{{item.residueClusteringNum}}人</view>
						<!-- 票名 -->
						<view class="goodsName">
							<text class="nameGoods">{{item.goodsName}}</text>
						</view>
						<view class="sc">游玩时间：{{item.playDate}}<text style="color: #007A69;margin-left: 10rpx;">{{item.playTime}}</text></view>
						<view class="sc">出海{{item.playLength}}小时 ·{{item.playTime}}截止</view>
						<!-- 价格&预定 -->
						<view class="price">
							<view class="price_left">
								<text class="rmb">￥</text>
								<text class="now_price">{{item.avePrice}}</text>
								<text class="bottom_price">人</text>
							</view>
							<view class="price_right"
								@click.native="toHref('/pagesTrip/fishJiale2/goodDetail?id='+item.id)">
								<text class="before_buy">{{openId==item.openId?'查看':'去拼船'}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<nodata class="scenspots " v-if="data.length == 0"></nodata>
	</view>
</template>

<script>
	import nodata from '@/compoments/NoData/index1.vue'
	export default {
		components: {
			nodata
		},
		data() {
			return {
				openId: '',
				jt: 'https://i.ringzle.com/file/20240228/e38ed46e3b974716be28edf501ab1059.png',
				jtt: 'https://i.ringzle.com/file/20240228/f3829b8038934e2f98dce6508c5bf771.png',
				jtb: 'https://i.ringzle.com/file/20240228/4b4de6d9e22241be9f209e164caec2c2.png',
				numSort: 0,
				pricesort: 0, //1降序 2升序 0随机
				timeNum: 0,
				h: uni.getSystemInfoSync().windowHeight,
				mt: uni.getSystemInfoSync().statusBarHeight + 44,
				data: [],
			};
		},
		onLoad(option) {
			//this.data=JSON.parse(option.data);
			if(uni.getStorageSync('userInfo')) this.openId = JSON.parse(uni.getStorageSync('userInfo')).openId;
			this.getData();
		},
		methods: {
			getData() {
				this.$api
					.get("/scenic/api/goods/queryGoodsList/1748948099092451329")
					.then((res) => {
						if (res.data.code === 0) {
							this.data = res.data.data.joinBoat || []; //拼船
						} else this.$showModal(res.data.msg);
					});
			},
			//价格排序
			sortPrice() {
				this.pricesort=!this.pricesort;
				let type=this.pricesort;
				this.data.sort(function(a, b) {
					if (!type) { //降序
						return b.avePrice - a.avePrice;
					} else{
						return a.avePrice - b.avePrice; //	升序
					}
				});
			},
			//人数排序
			sortNum() {
				this.numSort=!this.numSort;
				let type=this.numSort;
				this.data.sort(function(a, b) {
					if (!type) { //降序
						return parseFloat(b.clusteringNum) - parseFloat(a.clusteringNum);
					} else {
						return parseFloat(a.clusteringNum) - parseFloat(b.clusteringNum); //	升序
					}
				});
			},
			//时间排序
			sortTime() {
				this.timeNum=!this.timeNum;
				let type=this.timeNum;
				this.data.sort(function(a, b) {
					if (!type) { //降序
						return parseFloat(b.playTime) - parseFloat(a.playTime);
					} else{
						return parseFloat(a.playTime) - parseFloat(b.playTime); //	升序
					}
				});
			},
			
			toHref(url) {
				uni.navigateTo({
					url: url,
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	page,
	.page {
		background-color: #F5F8FA;
		height: 100%;
	}

	.banner {
		width: 100%;
		height: 274rpx;
	}

	.jd_sticky {
		position: sticky;
		z-index: 999;
	}

	.searchCondition {
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		flex-direction: row;
		padding: 22rpx 0;

		.item {
			margin: 0 40rpx;

			&>view {
				display: flex;
				line-height: 37rpx;
				align-items: center;

				text {
					font-size: 26rpx;
					color: #666;
				}

				image {
					width: 32rpx;
					height: 32rpx;
				}
			}

			.u-icon {
				justify-content: center;
			}
		}

	}

	.card {
		display: flex;
		justify-content: space-between;
		padding: 20rpx;
		position: relative;
		background-color: #fff;
		box-sizing: border-box;
		width: calc(100% - 40rpx);
		margin: 0 auto 20rpx;
		border-radius: 16rpx;

		.me {
			width: 98rpx;
			height: 34rpx;
			border-radius: 16rpx 0 18rpx 0;
			background-color: #FEB000;
			color: #fff;
			font-size: 20rpx;
			line-height: 34rpx;
			left: 20rpx;
			top: 20rpx;
			position: absolute;
			text-align: center;
		}

		.card_pic {
			width: 220rpx;
			min-width: 220rpx;
			height: 256rpx;
			// background-color: teal;

			image {
				border-radius: 10rpx;
				width: 100%;
				height: 100%;
			}
		}

		.card_text {
			margin-left: 24rpx;
			width: 200rpx;
			flex:1;
		}

		.num {
			width: 140rpx;
			height: 52rpx;
			border-radius: 26rpx;
			background-color: #F0F8F6;
			font-size: 26rpx;
			color: #007A69;
			line-height: 52rpx;
			position: absolute;
			right: 10rpx;
			top: 20rpx;
			text-align: center;
		}

		.nameGoods {
			box-sizing: border-box;
			font-size: 36rpx;
			font-weight: 700;
			width: 220px;
			padding-top: 10rpx;
			padding-right: 110rpx;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			display: inline-block;
			line-height: 36rpx;
		}

		.sc {
			margin: 24rpx 0;
			font-size: 26rp;
			color: #777;
		}

		.titleFlag {
			margin-bottom: 10rpx;

		}

		.flagText {
			font-size: 22rpx;
			border-radius: 4rpx;
			padding: 6rpx 8rpx;
			color: #597BA9;
			background: #F5F8FA;
		}

		.price {
			display: flex;
			justify-content: space-between;

			&.mt {
				margin-top: 46rpx;
			}
		}

		.rmb {
			font-size: 24rpx;
			color: #FF3E3E;
		}

		.now_price {
			font-size: 40rpx;
			color: #FF3E3E;
			font-weight: 700;
		}

		.bottom_price {
			font-size: 24rpx;
			color: #FF3E3E;
		}

		.before_price {
			font-size: 20rpx;
			color: #999990;
			text-decoration: line-through;
		}

		.price_right {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 140rpx;
			height: 56rpx;
			border-radius: 28rpx;
			background-color: #007A69;
			// margin-bottom: 5rpx;
		}

		.before_buy {
			color: #fff;
			font-size: 24rpx;
		}

	}
</style>